@extends('admin.common.app')
@section('cont')
<section class="Hui-article-box">
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span>教师中心
        <span class="c-gray en">&gt;</span>添加课程表
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
            <i class="Hui-iconfont">&#xe68f;</i>
        </a>
    </nav>
    <article class="cl pd-20">
        @include('admin.common.msg')
        <form action="{{ route('admin.student_course.store') }}" method="post" class="form form-horizontal" id="form-admin-add">
           @csrf
            {{--验证老师是否存在--}}
            <input type="hidden" name="teachers_id" id="teachers_id" value="">
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>班级名称：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{{old('classes')}}" placeholder="请输入班级名称" id="classes" name="classes" autocomplete="off">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>老师名字：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input onchange="opear(this);" type="text" class="input-text" value="{{old('tracher')}}" placeholder="请输入老师名字" id="tracher" name="teacher" autocomplete="off">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">上课时间：</label>
                <div class="formControls col-xs-8 col-sm-9">
                        <span class="select-box">
				            <select class="select" name="schooltime" size="1">
                                @foreach(config('student_course.schooltime') as $itme)
					            <option value="{{$itme}}">{{$itme}}</option>
                                @endforeach
				            </select>
                        </span>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>星期：</label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                    @foreach(config('student_course.week') as $week)
                    <div class="radio-box">
                        <input type="radio" name="week" value="{{$week}}" >
                        <label for="sex-1">{{$week}}</label>
                    </div>
                    @endforeach
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>星期：</label>
                <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                    @foreach(config('student_course.subject') as $subject)
                        <div class="radio-box">
                            <input type="radio" name="subject" value="{{$subject}}" >
                            <label for="sex-1">{{$subject}}</label>
                        </div>
                    @endforeach
                </div>
            </div>

            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;添加课程表&nbsp;&nbsp;">
                </div>
            </div>
        </form>
    </article>
</section>
@endsection
@section('js')
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
    <script type="text/javascript">
        //判断老师是否存在
        function opear(obj){
            var teacher = $(obj).val();
            var url="{{ route('admin.student_course.store') }}";
            var _token='{{csrf_token()}}';
           $.ajax({
               url,
               type:'POST',
               data:{teacher,_token},
               success:(data)=> {
                  if (data.status==0){
                      //老师id
                      let teacher=data.teacher;
                   $('#teachers_id').val(teacher);
                  }else {
                      layer.msg(data.msg,{
                          icon:2,
                          time:2000
                      },function () {
                          $(obj).val('');
                      })
                  }
               }
           })

        };
        $(function(){
            $('.skin-minimal input').iCheck({
                checkboxClass: 'icheckbox-blue',
                radioClass: 'iradio-blue',
                increaseArea: '20%'
            });

            $("#form-admin-add").validate({
                rules:{
                    phone:{
                        required:true,
                        phone:true
                    },
                    email:{
                        required:true,
                        email:true,
                    },
                    username:{
                        required:true,
                        minlength:4,
                        maxlength:16
                    },
                    truename:{
                        required:true,
                        isChinese:true
                    },
                    password:{
                        required:true,
                    },
                    password_confirmation:{
                        required:true,
                        equalTo: "#password"
                    },
                },
                message:{
                    username:{
                        required:'用户名不能为空',
                        minlength:'用户名长度必须大于4位',
                        maxlength:'用户名不能超过16位'
                    },
                    truename:{
                        required:'姓名不能为空',
                    },
                    password:{
                        required:'初始密码不能为空',
                    },
                    password_confirmation:{
                        required:'确认密码不能为空',
                        equalTo: '两次密码不一样'
                    },
                    phone:{
                        required:'手机号不能为空',
                    },
                    email:{
                        required:'邮箱不能为空',
                        email:'你输入的不是邮箱',
                    },
                },
                onkeyup:false,
                success:"valid",
                submitHandler: function (form) {
                    // 表单提交
                    form.submit();
                }
            });
            // 自定义验证规则
            // 邮政编码验证
            jQuery.validator.addMethod("phone", function (value, element) {
            //    var reg1 = /^\+86-1[3-9]\d{9}$/;
                var reg2 = /^1[3-9]\d{9}$/;
                var ret = reg1.test(value);
                return this.optional(element) || ret;
            }, "请输入正确的手机号码");
        });
    </script>

@endsection
